package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 🐱🐱🐱
 * @Date: 2025/8/22 10:28
 * @Description:
 **/
@Api(tags = "商品SKU接口")
@RestController
@RequestMapping("admin/product")
public class SkuManageController {
    @Resource
    private ManageService manageService;


    /**
     * 根据spuId 查询spuImageList
     * @param spuId
     * @return
     */
    @ApiOperation("根据spuId 查询spuImageList")
    @GetMapping("spuImageList/{spuId}")
    public Result spuImageList(@PathVariable("spuId") Long spuId){
       List<SpuImage> list = manageService.spuImageList(spuId);
       return Result.ok(list);
    }

    /**
     * 根据spuId查询 销售属性 平台属性 图片 海报
     * @param spuId
     * @return
     */
    @GetMapping("spuSaleAttrList/{spuId}")
    public Result getSpuSaleAttrList(@PathVariable("spuId") Long spuId) {
       List<SpuSaleAttr> spuSaleAttrList = manageService.getSpuSaleAttrList(spuId);
       return Result.ok(spuSaleAttrList);
    }

    /**
     * 添加sku
     * @param skuInfo
     * @return
     */
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }


    /**
     * SKU分页列表
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list/{page}/{limit}")
    public Result index(@PathVariable Long page
            ,@PathVariable Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
      IPage<SkuInfo> list = manageService.index(skuInfoPage);
      return Result.ok(list);

    }

    /**
     * 商品上架
     * @param skuId
     * @return
     */
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){
        manageService.onSale(skuId);
        return Result.ok();
    }

    /**
     * 商品下架
     * @param skuId
     * @return
     */
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        manageService.cancelSale(skuId);
        return Result.ok();
    }

}
